home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connectio…eloper Series 2005 March / Dev.CD Mar 05.iso / What's New / Technical Notes and Q&As / ADC Reference Library / qa / qa2001 / downloads / qa1027.hqx / DrawUnicodeString / DrawUnicodeString.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-16  |  5.9 KB  |  149 lines

  1. /*
  2.     File: DrawUnicodeString.h
  3.     
  4.     Description:
  5.         Routines for drawing unicode strings using ATSUI.  
  6.  
  7.     Copyright:
  8.         © Copyright 2001 Apple Computer, Inc. All rights reserved.
  9.     
  10.     Disclaimer:
  11.         IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  12.         ("Apple") in consideration of your agreement to the following terms, and your
  13.         use, installation, modification or redistribution of this Apple software
  14.         constitutes acceptance of these terms.  If you do not agree with these terms,
  15.         please do not use, install, modify or redistribute this Apple software.
  16.  
  17.         In consideration of your agreement to abide by the following terms, and subject
  18.         to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  19.         copyrights in this original Apple software (the "Apple Software"), to use,
  20.         reproduce, modify and redistribute the Apple Software, with or without
  21.         modifications, in source and/or binary forms; provided that if you redistribute
  22.         the Apple Software in its entirety and without modifications, you must retain
  23.         this notice and the following text and disclaimers in all such redistributions of
  24.         the Apple Software.  Neither the name, trademarks, service marks or logos of
  25.         Apple Computer, Inc. may be used to endorse or promote products derived from the
  26.         Apple Software without specific prior written permission from Apple.  Except as
  27.         expressly stated in this notice, no other rights or licenses, express or implied,
  28.         are granted by Apple herein, including but not limited to any patent rights that
  29.         may be infringed by your derivative works or by other works in which the Apple
  30.         Software may be incorporated.
  31.  
  32.         The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  33.         WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  34.         WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35.         PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  36.         COMBINATION WITH YOUR PRODUCTS.
  37.  
  38.         IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  39.         CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  40.         GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41.         ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  42.         OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  43.         (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  44.         ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45.  
  46.     Change History (most recent first):
  47.         Wed, Feb 16, 2001 -- created
  48.         Wed, Apr 02, 2001 -- added unicode only routines
  49. */
  50.  
  51. #ifndef __DRAWCFSTRING__
  52. #define __DRAWCFSTRING__
  53.  
  54.  
  55. #if TARGET_API_MAC_CARBON
  56.  
  57. #ifdef __APPLE_CC__
  58. #include <Carbon/Carbon.h>
  59. #else
  60. #include <Carbon.h>
  61. #endif
  62.  
  63. #else
  64.  
  65. #include <Types.h>
  66. #include <ATSUnicode.h>
  67. #include <Appearance.h>
  68. #include <FixMath.h>
  69.  
  70. #endif
  71.  
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75.  
  76.  
  77.     /* MakeThemeATSUIStyle creates a simple ATSUI style record that
  78.     based on the current theme fond that can be used in calls to the
  79.     RenderUnicodeString and MeasureUnicodeString routines.  The
  80.     style record created is based on the font specified in the themeFontID
  81.     parameter.  */ 
  82. OSStatus MakeThemeATSUIStyle(ThemeFontID themeFontID, ATSUStyle *theStyle);
  83.  
  84.     /* MakeSimpleATSUIStyle creates a simple ATSUI style record that
  85.     can be used in calls to the RenderUnicodeString and MeasureUnicodeString
  86.     routine. The ATSUI style record will be constructed using the indicated font,
  87.     size, style and colour.  */ 
  88. OSStatus MakeSimpleATSUIStyle(StringPtr fontName, short fontSize, short qdStyle,
  89.             RGBColor *fontColor, ATSUStyle *theStyle);
  90.  
  91.     /* RenderUnicodeString renders a CFString at (h, v) in the current grafport
  92.     using ATSUI using the style specified in the atsui style record.  If maxwidth
  93.     is non-zero, then the text will be wordwrapped in such a way that it will
  94.     not exceed the width when drawn.  */
  95. OSStatus RenderUnicodeString(ConstUniCharArrayPtr iText, UniCharCount iTextLength,
  96.     ATSUStyle theStyle, short h, short v, short maxwidth);
  97.  
  98.  
  99.     /* MeasureUnicodeString returns a rectangle where the CFStringRef would
  100.     be drawn if it were drawn at location (0,0) -- just like QDTextBounds. if
  101.     maxwidth is non-zero, then the text will be wordwrapped in such a way
  102.     that it will not exceed the width when drawn.  */
  103. OSStatus MeasureUnicodeString(ConstUniCharArrayPtr iText,
  104.     UniCharCount iTextLength, ATSUStyle theStyle, short maxwidth, Rect *bounds);
  105.  
  106.  
  107. #if TARGET_API_MAC_CARBON
  108.  
  109.     /* carbon routines */
  110.  
  111.     /* extracts the Unicode data from the CFString and 
  112.     calls RenderUnicodeString. */
  113. OSStatus RenderCFString(CFStringRef theString, ATSUStyle theStyle, 
  114.     short h, short v, short maxwidth);
  115.  
  116.  
  117.     /* MeasureCFString extracts the Unicode data from the 
  118.     CFString and calls MeasureUnicodeString. */
  119. OSStatus MeasureCFString(CFStringRef theString, ATSUStyle theStyle, 
  120.     short maxwidth, Rect *bounds);
  121.  
  122. #endif
  123.  
  124.  
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128.  
  129. #endif
  130.  
  131.  
  132. /* Tips for optimal performance:
  133.  
  134. (A)    If at all possible, do not call the routine MakeThemeATSUIStyle or the routine
  135.     MakeSimpleATSUIStyle more than once to create the styles your application
  136.     requires.  cache the style records created among your application's globals
  137.     and use them whenever you need to draw text.
  138.  
  139. (B)    Set maxwidth to zero if you know all your text should reside on one
  140.     line.
  141.     
  142.     The routines RenderUnicodeString, MeasureUnicodeString, RenderCFString, 
  143.     and MeasureCFString include a maxwidth parameter.  If you look at the source
  144.     you will notice that when this parameter is non-zero, a separate code path
  145.     is used that attempts to calculate line breaks at the indicated width.  This
  146.     takes extra time to do.  If you know there are no line breaks, don't ask
  147.     for them to be calculated.
  148.  
  149. */